package ro.qi.framework.sys.common;

public class PhoneNumber {

	private String phoneNumber = "";
	
	private String areaCode = "";
	private String firstPair = "";
	private String lastPair = "";
	private String extension = "";
	
	public String getPhoneNumber() {
		return phoneNumber;
	}

	public PhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;

		if (phoneNumber.length() > 0) {
			if (phoneNumber.length() >= 10) { 
				setAreaCode(phoneNumber.substring(0, 3));
				setFirstPair(phoneNumber.substring(3, 6));
				setLastPair(phoneNumber.substring(6, 10));
				if (phoneNumber.indexOf("/") != -1) {
					setExtension(phoneNumber.substring(phoneNumber.indexOf("/")+1));
				}
			}
		}
	}

	public PhoneNumber(String areaCode, String firstPair, String lastPair) {
		this.phoneNumber = areaCode.trim() + firstPair.trim() + lastPair.trim();
		this.areaCode = areaCode;
		this.firstPair = firstPair;
		this.lastPair = lastPair;
	}

	public PhoneNumber(String areaCode, String firstPair, String lastPair, String extension) {
		if (extension.trim().length() > 0) {
			this.phoneNumber = areaCode.trim() + firstPair.trim() + lastPair.trim() + "/" + extension;
		} else {
			this.phoneNumber = areaCode.trim() + firstPair.trim() + lastPair.trim();
		}
		this.areaCode = areaCode;
		this.firstPair = firstPair;
		this.lastPair = lastPair;
		this.extension = extension;
	}

	public String getFormatedNumber() {
		String formatedPhoneNumber = "";

		if (phoneNumber.length() > 0) {
			formatedPhoneNumber = "" + getAreaCode() + "-" + getFirstPair() + "-" + getLastPair();
			String extension = getExtension();
			if (extension.length() > 0) {
				formatedPhoneNumber = formatedPhoneNumber + " Ext.: " + getExtension();
			}
		}

		return formatedPhoneNumber;
	}
	
	public String getAreaCode() {
		return areaCode;
	}
	
	public String getFirstPair() {
		return firstPair;
	}
	
	public String getLastPair() {
		return lastPair;
	}
	
	public String getExtension() {
		return extension;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public void setExtension(String extension) {
		this.extension = extension;
	}

	public void setFirstPair(String firstPair) {
		this.firstPair = firstPair;
	}

	public void setLastPair(String lastPair) {
		this.lastPair = lastPair;
	}

}
